package lock.wait;

/**
 * @author zhangxin
 * @date 2020/9/28
 */
public class Test {

    private Object mutex;

    public Test(Object mutex) {
        this.mutex = mutex;
    }

    public static void main(String[] args) {
        Object lock = new Object();
        Test test = new Test(lock);
        new Thread(()->{
            test.testStatic();
        }).start();

        Test test2 = new Test(lock);
        new Thread(()->{
            test2.testStatic2();
        }).start();
    }

    public void testStatic() {
        synchronized (mutex) {
            try {
                mutex.wait();
                System.out.println("begin ...");
                Thread.sleep(100);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }

    public void testStatic2() {
        synchronized (mutex) {
        mutex.notify();
            try {
                System.out.println("testStatic2...");
                Thread.sleep(1020);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
